package net.suncaper.hotel.common.utils;

import lombok.Data;

/**
 * 统一响应结果
 */
@Data
public class Result {
    private boolean success;
    private String message;
    private Object data;
    private int code;

    private Result() {}

    public static Result success() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    public static Result success(Object data) {
        Result result = success();
        result.setData(data);
        return result;
    }

    public static Result success(String message, Object data) {
        Result result = success();
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static Result error(String message) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(500);
        result.setMessage(message);
        return result;
    }

    public static Result error(int code, String message) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static Result fail(String message) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(400);
        result.setMessage(message);
        return result;
    }
}